package com.jungle.client;

import com.jungle.bfi.domain.vo.DatasetVo;
import com.jungle.client.control.BasicDialog;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.net.URL;
import java.util.function.Consumer;

import static com.jungle.client.FxApplication.bundle;

@Slf4j
public class DatasetEditController extends BasicDialog<DatasetVo> {
    @FXML
    private TextField nameField;
    @FXML
    private TextField descriptionField;
    private String id;

    @Override
    public void loadData(DatasetVo data) {
        nameField.setText(data.getName());
        descriptionField.setText(data.getDescription());
    }


    public DatasetVo storeData() {
        DatasetVo data = new DatasetVo();
        data.setId(this.id);
        data.setName(nameField.getText());
        data.setDescription(descriptionField.getText());
        return data;
    }

    private static final URL FXML_URL = DatasetEditController.class.getResource("dataset-edit.fxml");
    private static final String TITLE = bundle.getString("dataset.dialog.title");

    public static void showAddDialog(DatasetVo dataSetVo, Consumer<DatasetVo> consumer) throws IOException {

        String title = bundle.getString("dialog.title.prefix.add") + TITLE;

        new DatasetEditController().showDialog(FXML_URL, title, dataSetVo, consumer);
    }

    public static void showEditDialog(DatasetVo dataSetVo, Consumer<DatasetVo> consumer) throws IOException {

        String title = bundle.getString("dialog.title.prefix.edit") + TITLE;

        new DatasetEditController().showDialog(FXML_URL, title, dataSetVo, consumer);
    }

}
